/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('grace', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AnalysisConfig {
  badThroughputThreshold?: double(name='badThroughputThreshold'),
  fullGCFrequentIntervalThreshold?: double(name='fullGCFrequentIntervalThreshold'),
  highHeapUsageThreshold?: double(name='highHeapUsageThreshold'),
  highHumongousUsageThreshold?: double(name='highHumongousUsageThreshold'),
  highMetaspaceUsageThreshold?: double(name='highMetaspaceUsageThreshold'),
  highOldUsageThreshold?: double(name='highOldUsageThreshold'),
  highPromotionThreshold?: double(name='highPromotionThreshold'),
  highSysThreshold?: double(name='highSysThreshold'),
  longConcurrentThreshold?: double(name='longConcurrentThreshold'),
  longPauseThreshold?: double(name='longPauseThreshold'),
  lowUsrThreshold?: double(name='lowUsrThreshold'),
  oldGCFrequentIntervalThreshold?: double(name='oldGCFrequentIntervalThreshold'),
  smallGenerationThreshold?: double(name='smallGenerationThreshold'),
  timeRange?: {
    end?: double(name='end'),
    start?: double(name='start'),
  }(name='timeRange'),
  tooManyOldGCThreshold?: double(name='tooManyOldGCThreshold'),
  youngGCFrequentIntervalThreshold?: double(name='youngGCFrequentIntervalThreshold'),
}

model FileInfo {
  analyzeProgress?: {
    message?: string(name='message'),
    percent?: double(name='percent'),
    state?: string(name='state'),
  }(name='analyzeProgress'),
  creationTime?: long(name='creationTime'),
  displayName?: string(name='displayName'),
  labels?: string(name='labels'),
  name?: string(name='name'),
  requestId?: string(name='requestId'),
  shared?: boolean(name='shared'),
  size?: long(name='size'),
  transferProgress?: {
    totalSize?: long(name='totalSize'),
    transferredSize?: long(name='transferredSize'),
  }(name='transferProgress'),
  transferState?: string(name='transferState'),
  type?: string(name='type'),
}

model PhaseStatisticItem {
  count?: int32(name='count'),
  durationAvg?: double(name='durationAvg'),
  durationMax?: double(name='durationMax'),
  durationTotal?: double(name='durationTotal'),
  intervalAvg?: double(name='intervalAvg'),
  intervalMin?: double(name='intervalMin'),
  name?: string(name='name'),
}

model AnalyzeFileRequest {
  keepUnreachableObjects?: boolean(name='keepUnreachableObjects', example='true'),
  name?: string(name='name', example='123-456-file.log'),
  token?: string(name='token', example='6e54e9d5-3147-458e-a85d-bae8722de747'),
}

model AnalyzeFileResponseBody = {
  fileName?: string(name='fileName', example='207076258906603549-1667270208299-heap_dump_11.195.186.232_1667269965442.bin'),
  requestId?: string(name='requestId', example='B14EC7CC-5181-582F-8EB7-6DB142FB529F'),
}

model AnalyzeFileResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: AnalyzeFileResponseBody(name='body'),
}

async function analyzeFileWithOptions(request: AnalyzeFileRequest, headers: map[string]string, runtime: Util.RuntimeOptions): AnalyzeFileResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.keepUnreachableObjects)) {
    query['keepUnreachableObjects'] = request.keepUnreachableObjects;
  }
  if (!Util.isUnset(request.name)) {
    query['name'] = request.name;
  }
  if (!Util.isUnset(request.token)) {
    query['token'] = request.token;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'AnalyzeFile',
    version = '2022-06-06',
    protocol = 'HTTPS',
    pathname = `/AnalyzeFile`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function analyzeFile(request: AnalyzeFileRequest): AnalyzeFileResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return analyzeFileWithOptions(request, headers, runtime);
}

model GetFileRequest {
  name?: string(name='name', example='1597871211794192-1682563156700-402185-1682563123810-bbbbb'),
  token?: string(name='token', example='924cb178-32e6-453a-a553-83289f9f494c'),
}

model GetFileResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: FileInfo  
}

async function getFileWithOptions(request: GetFileRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetFileResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.name)) {
    query['name'] = request.name;
  }
  if (!Util.isUnset(request.token)) {
    query['token'] = request.token;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetFile',
    version = '2022-06-06',
    protocol = 'HTTPS',
    pathname = `/GetFile`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getFile(request: GetFileRequest): GetFileResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getFileWithOptions(request, headers, runtime);
}

model UploadFileByOSSRequest {
  bucketName?: string(name='bucketName', example='grace-storage'),
  displayName?: string(name='displayName', example='heap.bin'),
  endpoint?: string(name='endpoint', description='oss endpoint', example='https://oss-cn-hangzhou.aliyuncs.com'),
  objectName?: string(name='objectName', example='heap.bin'),
  type?: string(name='type', example='thread_dump'),
}

model UploadFileByOSSResponseBody = {
  name?: string(name='name', example='1597871211794192-1665457027646-grace-storage1-heap.bin'),
  requestId?: string(name='requestId', example='E7D6CC4E-C216-5313-A9A5-B5DA619ED431'),
}

model UploadFileByOSSResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UploadFileByOSSResponseBody(name='body'),
}

async function uploadFileByOSSWithOptions(request: UploadFileByOSSRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UploadFileByOSSResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.bucketName)) {
    query['bucketName'] = request.bucketName;
  }
  if (!Util.isUnset(request.displayName)) {
    query['displayName'] = request.displayName;
  }
  if (!Util.isUnset(request.endpoint)) {
    query['endpoint'] = request.endpoint;
  }
  if (!Util.isUnset(request.objectName)) {
    query['objectName'] = request.objectName;
  }
  if (!Util.isUnset(request.type)) {
    query['type'] = request.type;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UploadFileByOSS',
    version = '2022-06-06',
    protocol = 'HTTPS',
    pathname = `/UploadFileByOSS`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function uploadFileByOSS(request: UploadFileByOSSRequest): UploadFileByOSSResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return uploadFileByOSSWithOptions(request, headers, runtime);
}

model UploadFileByURLRequest {
  displayName?: string(name='displayName', example='atp_stack.log'),
  type?: string(name='type', example='heap_dump'),
  url?: string(name='url', example='https://bucket.oss-cn-hangzhou.aliyuncs.com/file.log'),
}

model UploadFileByURLResponseBody = {
  name?: string(name='name', example='1597871211794192-1682567255445-bbbbb'),
  requestId?: string(name='requestId', example='D052C0F4-5884-5B01-A8CC-D63B9A549B6C'),
}

model UploadFileByURLResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: UploadFileByURLResponseBody(name='body'),
}

async function uploadFileByURLWithOptions(request: UploadFileByURLRequest, headers: map[string]string, runtime: Util.RuntimeOptions): UploadFileByURLResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.displayName)) {
    query['displayName'] = request.displayName;
  }
  if (!Util.isUnset(request.type)) {
    query['type'] = request.type;
  }
  if (!Util.isUnset(request.url)) {
    query['url'] = request.url;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'UploadFileByURL',
    version = '2022-06-06',
    protocol = 'HTTPS',
    pathname = `/UploadFileByURL`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function uploadFileByURL(request: UploadFileByURLRequest): UploadFileByURLResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return uploadFileByURLWithOptions(request, headers, runtime);
}

